package com.itheima.controller.backend.Controller;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.controller.backend.Service.CheckGroupService;
import com.itheima.pojo.CheckGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
@Api(tags ="检查组相关接口")
@Slf4j
public class CheckGroupController {

    @Autowired
    private CheckGroupService checkGroupService;

    @PostMapping("/add")
    @ApiOperation("新增检查组")
    public Result addCheckGroup(@RequestBody CheckGroup checkGroup, @RequestParam String checkitemIds){
        log.info("新增检查组:checkGroup:{};checkitemIds:{}",checkGroup,checkitemIds);
        checkGroupService.addCheckGroup(checkGroup,checkitemIds);
        return new Result(true,"新增检查组成功");
    }

    @GetMapping("/deleteById")
    @ApiOperation("根据id删除检查组")
    public Result deleteById(@RequestParam Integer id){
        log.info("根据id删除检查组:{}",id);
        checkGroupService.deleteById(id);
        return new Result(true,"删除检查组成功");
    }

    @GetMapping("/findCheckGroupIdsBySetmealId")
    @ApiOperation("根据套餐id查询关联的检查项id")
    public Result findCheckGroupIdsBySetmealId(@RequestParam Integer setmealId){
        log.info("根据套餐id查询关联的检查项id:{}",setmealId);
        List<Integer> checkGroupIds = checkGroupService.findCheckGroupIdsBySetmealId(setmealId);
        return new Result(true,"查询成功",checkGroupIds);
    }

    @PostMapping("/findPage")
    @ApiOperation("分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询:{}",queryPageBean);
        return checkGroupService.findPage(queryPageBean,queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
    }

    @PostMapping("/edit")
    @ApiOperation("编辑")
    public Result edit(@RequestBody CheckGroup checkGroup,@RequestParam String checkitemIds){
        log.info("编辑检查组:{},{}",checkGroup,checkitemIds);
        checkGroupService.edit(checkGroup,checkitemIds);
        return new Result(true,"编辑检查组成功");
    }

    @GetMapping("/findAll")
    @ApiOperation("查询所有检查组")
    public Result findAll(){
        log.info("查询所有检查组");
        List<CheckGroup> checkGroups = checkGroupService.findAll();
        return new Result(true,"查询所有检查组成功",checkGroups);
    }

    @GetMapping("/findById")
    @ApiOperation("根据id查询检查组")
    public Result findById(@RequestParam String id){
        log.info("根据id查询检查组:{}",id);
        CheckGroup checkGroup = checkGroupService.findById(Integer.parseInt(id));
        return new Result(true,"查询检查组成功",checkGroup);
    }

}
